package com.pc.ipushpin.common.manager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class ClientManager {
	
	private static Logger logger = LoggerFactory.getLogger(ClientManager.class);
	
	@Resource
	private AppUserModuleManager userModuleManager;

	@Resource
	private LabelModuleManager labelModuleManager;

	@Resource
	private StoreModuleManager storeModuleManager;
	
	/**
	 * 用户模块
	 * @param request
	 * @param req:component
	 * @return
	 */
	public Map<String, Object> userModule(String method,String version,Map<String, String> mapIn, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Integer> methodMap = new HashMap<String, Integer>() {
			{
				put("getWechatInfoByCode", 1);
				put("getUserInfo",2);
				put("addUserInfo",3);
				put("decryptUserInfo",4);
				put("getUserInfoByTel",5);
				put("sponsors",6);
				put("myCollect",7);
			}
		};
		switch (methodMap.get(method)) {
		case 1:
			if(version.equals("v1")){
				map = userModuleManager.getWechatInfoByCode(mapIn,request);
			}
			break;
		case 2:
			map = userModuleManager.getUserInfo(mapIn,request);
			break;
		case 3:
			map = userModuleManager.addUserInfo(mapIn,request);
			break;
		case 4:
			map = userModuleManager.decryptUserInfo(mapIn,request);
			break;
		case 5:
			map = userModuleManager.getUserInfoByTel(mapIn,request);
			break;
		default:
			map.put("code", "106");
			map.put("msg", "系统没有提供这个接口或者没有调用权限");
			map.put("success", false);
			break;
		}
		return map;
	}

	/**
	 * 标签模块
	 * @param request
	 * @param req:component
	 * @return
	 */
	public Map<String, Object> labelModule(String method,String version,Map<String, String> mapIn, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Integer> methodMap = new HashMap<String, Integer>() {
			{
				put("findAllByCompanyId", 1);
			}
		};
		switch (methodMap.get(method)) {
			case 1:
				map = labelModuleManager.findAllByCompanyId(mapIn,request);
				break;
			default:
				map.put("code", "106");
				map.put("msg", "系统没有提供这个接口或者没有调用权限");
				map.put("success", false);
				break;
		}
		return map;
	}

	/**
	 * 门店模块
	 * @param request
	 * @param req:component
	 * @return
	 */
	public Map<String, Object> storeModule(String method,String version,Map<String, String> mapIn, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Integer> methodMap = new HashMap<String, Integer>() {
			{
				put("findAllByLabelIds", 1);
			}
		};
		switch (methodMap.get(method)) {
			case 1:
				map = storeModuleManager.findAllByLabelIds(mapIn,request);
				break;
			default:
				map.put("code", "106");
				map.put("msg", "系统没有提供这个接口或者没有调用权限");
				map.put("success", false);
				break;
		}
		return map;
	}

}
